package com.taxi.driver.module.main.mine.wallet.withdrawalrecord;

import com.qianxx.utils.RxUtil;
import com.taxi.driver.R;
import com.taxi.driver.common.BasePresenter;
import com.taxi.driver.data.user.UserRepository;
import com.taxi.driver.module.vo.WithdrawaleRecordVO;

import javax.inject.Inject;

public class WithdrawaleRecordPresenter extends BasePresenter implements WithdrawaleRecordContract.Presenter {
    WithdrawaleRecordContract.View mView;
    UserRepository mUserRepository;

    @Inject
    public WithdrawaleRecordPresenter(UserRepository userRepository, WithdrawaleRecordContract.View view) {
        this.mUserRepository = userRepository;
        this.mView = view;
    }

    @Override
    public void reqWithdrawaleRecord(int nowPage) {
        mUserRepository.widthdrawalRecord(nowPage)
                .flatMapIterable(entities -> entities)
                .map(WithdrawaleRecordVO::createFrom)
                .toList()
                .compose(RxUtil.applySchedulers())
                .doOnSubscribe(() -> mView.showLoadingView(false))
                .doAfterTerminate(() -> mView.hideLoadingView())
                .subscribe(vo -> {
                    mView.showWithdrawaleRecord(vo);
                }, ex -> {
                    showNetworkError(ex, R.string.network_error, mView, mUserRepository);
                });
    }
}
